// pages/consultation/answered/answered.js
const app = getApp()
var help = require('../../../utils/help.js');
var login = require('../../../utils/login.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imageUrl: app.data.imageUrl,

    id: 0,
    data: {},
    is_msg: 0,
    msg_id:0,
    huida:'',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (options.id) {
      this.setData({
        id: options.id
      })
    }
    if (options.is_msg) {
      this.setData({
        is_msg: options.is_msg
      })
    }
    if (options.msg_id) {
      this.setData({
        msg_id: options.msg_id
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.loadBaseData();
  },

  loadBaseData: function () {
    var that = this;
    //医生
    help.get(app.data.apiUrl + 'Zxorder/orderInfo', {
      token: app.data.userInfo ? app.data.userInfo.token : '',
      id: that.data.id,
      msg_id: that.data.msg_id
    }, that, function (res, that) {
      var result = res.data;
      // console.log(result);
      if (result.code == 1) {
        that.setData({
          data: result.data,
        })
      }

    });
  },

  set_huida: function (e) {
    this.setData({
      huida: e.detail.value
    })
  },

  huida: function () {
    var that = this;
    //回答
    help.get(app.data.apiUrl + 'Zxorder/huida', {
      token: app.data.userInfo ? app.data.userInfo.token : '',
      id: that.data.id,
      huida: that.data.huida
    }, that, function (res, that) {
      var result = res.data;
      // console.log(result);
      if (result.code == 1) {
        that.setData({
          huida:''
        })
        that.loadBaseData();
      } else {
        help.msg(result.msg)
      }

    });
  },
  del: function () {
    var that = this;
    //删除
    help.get(app.data.apiUrl + 'Zxorder/orderDelMsg', {
      token: app.data.userInfo ? app.data.userInfo.token : '',
      id: that.data.msg_id,
    
    }, that, function (res, that) {
      var result = res.data;
      // console.log(result);
      if (result.code == 1) {
       
        that.loadBaseData();
      } else {
        help.msg(result.msg)
      }

    });
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  // 预览图片
  showImg: function(e) {
    wx.previewImage({
      current: e.currentTarget.dataset.src, // 当前显示图片的http链接
      urls: this.data.data.msg_list[e.currentTarget.dataset.msgindex].images // 需要预览的图片http链接列表
    })
  }
})